package edu.ntu.im.p2ptrade.msg.handle;

import edu.ntu.im.p2ptrade.DialogHost;
import edu.ntu.im.p2ptrade.P2PTrade;
import edu.ntu.im.p2ptrade.Util;
import edu.ntu.im.p2ptrade.msg.PMessage;
import edu.ntu.im.p2ptrade.msg.QueryUser;
import net.jxta.endpoint.Message;

public class HeartBeatHandle implements PMessageHandle {

	public void handle(Message msg) {
		String peer = msg.getMessageElement(
				P2PTrade.getInstance().getAppName(), PMessage.PEER).toString();
		if (!peer.equals(P2PTrade.getInstance().getPeerName())) {
			if (!DialogHost.getInstance().haveMeetPeer(peer)) {
				System.out.println("dealing with peer:" + peer);
				QueryUser user = new QueryUser();
				Util.transdferMessageToPeer(user.getMessageToTransfer(), peer);
			}
			DialogHost.getInstance().meetPeer(peer);
		}
	}

}
